//
//  User.swift
//  swift-GWYWeiBo
//
//  Created by x on 2017/4/17.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class User: NSObject {
    
    /// 用户UID
    var id: Int = 0
    
    /// 好友显示名称
    var name: String?
    
    /// 性别，m：男、f：女、n：未知
    var gender: String?
    
    /// 用户头像地址（中图），50×50像素
    var profile_image_url: String?{
        didSet {
            if profile_image_url != nil {
                imageURL = URL(string: profile_image_url!)
            }
        }
    }
    
    /// 用于保存用户头像的URL
    var imageURL:URL?
    
    /// 是否是微博认证用户，即加V用户，true：是，false：否
    var verified:Bool = false
    
    /// 用户认证类型 -1 没有认证 0 认证用户 2,3,4企业认证 220 达人
    var verified_type:Int = -1{
        didSet {
            switch verified_type {
            case 0 :
                //这里应该还要判断是属于男还是 女
                verifiedImage = UIImage(named: "avatar_vip")
            case 2,3,5 :
                verifiedImage = UIImage(named: "avatar_enterprise_vip")
            case 220 :
                verifiedImage = UIImage(named: "avatar_grassroot")
            default:
                verifiedImage = nil
            }
        }
    }
    
    /// 保存当前用户的认证图标
    var verifiedImage:UIImage?
    
    /// 用会员等级
    var mbrank: Int = 0 {
        didSet {
            if mbrank > 0 && mbrank < 7 {
                mbrankImage = UIImage( named: "common_icon_membership_level\(mbrank)")
            }
        }
    }
    
    /// 保存用户会员等级图片
    var mbrankImage: UIImage?
    
    /// 字典转模型
    ///
    /// - Parameter dict: <#dict description#>
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeys(dict)
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    let tt = ["id","name","profile_image_url","verified","verified_type","gender"]
    /// 打印数据模型
    override var description: String {
        let dic = dictionaryWithValues(forKeys: tt)
        return "\(dic)"
    }
}
